package org.bluedream.core.module.service.bill.stkIn.dtl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import org.apache.commons.collections.map.HashedMap;
import org.bluedream.comm.utils.EmptyUtil;
import org.bluedream.core.module.base.BillDtlServiceImpl;
import org.bluedream.core.module.dao.bill.stkIn.dtl.StkInDtlDao;
import org.bluedream.core.module.entity.bill.stkIn.StkIn;
import org.bluedream.core.module.entity.bill.stkIn.dtl.StkInDtl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.Serializable;
import java.util.Map;

/**
 * @ClassName StkInDtlService
 * @Description TODO
 * @Author foxsand
 * @Data 2021-11-18 15:24
 * @Version
 */
@Service
@DS("master")
@Transactional(
        readOnly = true
)
public class StkInDtlService extends BillDtlServiceImpl<StkInDtlDao, StkInDtl> implements IService<StkInDtl> {
    private static final Logger logger = LoggerFactory.getLogger(StkInDtlService.class);

    @Override
    public StkInDtl getById(Serializable id) {
        if (EmptyUtil.isEmpty(id)){
            return new StkInDtl();
        }
        return super.getById(id);
    }

    public IPage<StkInDtl> findPage(StkIn head , String... args) {
        if (EmptyUtil.isEmpty(head.getBillNum())){
            return null;
        }else {
            StkInDtl entity = new StkInDtl(head.getBillNum());
            Map<String , Object> search = new HashedMap();
            search.put("StkInDtl.bill_type" , head.getBillType());
            search.put("StkInDtl.bill_num;eq" , entity.getBillNum());
            entity.setLimit((long) super.getListBySearch(entity , "bill_num" , entity.getBillNum()).size());
            entity.setPage(1L);
            System.out.println("current = " + entity.getPage() + ";size = " + entity.getLimit());
            IPage<StkInDtl> page = super.findPage(entity , true , search , args);
            return page;
        }
    }
}
